<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>购物车</title>
    <link rel="stylesheet" href="/css/style.css">
</head>
<body>
    <!-- 导航栏 -->
    <div style="width:100%;background:#fff;box-shadow:0 2px 5px rgba(0,0,0,0.05);padding:16px 0 8px 0;display:flex;justify-content:flex-end;align-items:center;position:sticky;top:0;z-index:10;">
        <a href="/admin/stock-warning" class="order-btn" style="margin-right:40px;width:auto;padding:6px 18px;background:#ff9800;">后台管理</a>
        <a href="/dishes" class="order-btn" style="margin-right:40px;width:auto;padding:6px 18px;">返回菜单</a>
        <a href="/logout" class="order-btn" style="margin-right:40px;width:auto;padding:6px 18px;background:#e44d26;">退出登录</a>
    </div>
    <div class="container">
        <h1>购物车</h1>
        <c:choose>
            <c:when test="${empty cart}">
                <p>购物车为空。</p>
            </c:when>
            <c:otherwise>
                <table style="width:100%;background:white;border-radius:8px;box-shadow:0 2px 5px rgba(0,0,0,0.1);">
                    <thead>
                    <tr>
                        <th>图片</th>
                        <th>菜品</th>
                        <th>单价</th>
                        <th>数量</th>
                        <th>小计</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${cart}" var="item">
                        <tr>
                            <td><img src="${item.imageUrl}" alt="${item.dishName}" style="width:60px;height:40px;"></td>
                            <td>${item.dishName}</td>
                            <td>￥${item.price}</td>
                            <td>${item.quantity}</td>
                            <td>￥${item.price * item.quantity}</td>
                            <td>
                                <form action="/cart/remove" method="post" style="display:inline;">
                                    <input type="hidden" name="dishId" value="${item.dishId}">
                                    <button type="submit" class="order-btn" style="padding:4px 10px;">移除</button>
                                </form>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
                <div style="margin:20px 0;text-align:right;font-size:1.2em;">
                    总计：<span style="color:#e44d26;">￥${total}</span>
                </div>
                <form action="/cart/clear" method="post" style="display:inline;">
                    <button type="submit" class="order-btn" style="background:#888;">清空购物车</button>
                </form>
                <a href="/dishes" class="order-btn" style="margin-left:10px;">继续点餐</a>
                <a href="/cart/checkout" class="order-btn" style="margin-left:10px;background:#4CAF50;">去结算</a>
            </c:otherwise>
        </c:choose>
    </div>
</body>
</html> 